package com.itheima.web.action;

import com.itheima.domain.Dep;
import com.itheima.service.DepService;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by Mr.King on 2017/3/4.
 */
//spring注解
@Component(value = "depAction")
@Scope(value = "prototype")
//struts2注解
@ParentPackage("struts-default")
@Namespace("/")
public class DepAction extends ActionSupport {

    @Autowired
    private DepService service;

    @Action(value = "dep_list",results = {@Result(name = "list",location="/index.jsp")})
    public String list(){
        List<Dep> list = service.getList();
        HttpServletRequest request = ServletActionContext.getRequest();
        request.setAttribute("list",list);
        return "list";
    }
}
